package Chapter1;

public class FindLinkCyleDemo {

    static class Node {
        int value;
        Node next;
    }


    public static void main(String[] args) {
        Node node = new Node();
        Node node1 = new Node();
        node.next = node1;
        Node node2 = new Node();
        node1.next = node2;
        node2.next = node;
        System.out.println(find(node));

    }

    public static boolean find(Node node) {
        if (node == null || node.next == null) {
            return false;
        }
        Node fast = node.next;
        Node slow = node;
        while (fast != null && fast.next != null) {
            if (fast == slow) {
                return true;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return false;
    }

}
